package com.ruoyi.web.controller.Base;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.domain.Ability_InstitutionInfor;
import com.ruoyi.service.Ability_InstitutionService;
import net.sf.jsqlparser.statement.select.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Institution")
public class InstitutionController extends BaseController {
    @Autowired
    Ability_InstitutionService ability_InstitutionService;
    @GetMapping("/selectByid/{id}")
    public AjaxResult selectInstitutionByID(@PathVariable("id") Integer id) {
        Ability_InstitutionInfor ability_InstitutionInfor = ability_InstitutionService.selectAbility_InstitutionInforById(id);
        if (ability_InstitutionInfor != null) {
            return AjaxResult.success(ability_InstitutionInfor);
        } else {
            return AjaxResult.warn("未找到该机构");
        }

    }
    @GetMapping("/list")
    public TableDataInfo selectInstitutionList(@RequestParam(required = false,value = "sername") String ip,
                                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, // 添加默认值可选
                                               @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        startPage();
        List<Ability_InstitutionInfor> list = ability_InstitutionService.selectAbility_InstitutionInforList();
       return getDataTable(list);
    }
    @GetMapping("/selectByname/{name}")
    public AjaxResult selectInstitutionByName(@PathVariable("name") String name) {

        Ability_InstitutionInfor ability_InstitutionInfor = ability_InstitutionService.selectAbility_InstitutionInforByName(name);
        if (ability_InstitutionInfor != null) {
            return AjaxResult.success(ability_InstitutionInfor);
        } else {
            return AjaxResult.warn("未找到该机构");
        }

    }
    @PostMapping("/addIns")
    public  AjaxResult insertInstitution(@RequestBody  Ability_InstitutionInfor ability_InstitutionInfor){
        System.out.println(ability_InstitutionInfor.getAccount());
        int result = ability_InstitutionService.insertAbility_InstitutionInfor(ability_InstitutionInfor);
        if(result>0){
            return AjaxResult.success("添加成功");
        }else {
            return AjaxResult.warn("添加失败");
        }
    }
    @PostMapping("/updateIns")
    public  AjaxResult updateInstitution(@RequestBody  Ability_InstitutionInfor ability_InstitutionInfor){
        int result = ability_InstitutionService.updateAbility_InstitutionInfor(ability_InstitutionInfor);
        if(result>0){
            return AjaxResult.success("修改成功");
        }else {
            return AjaxResult.warn("修改失败");
        }
    }
    @GetMapping("/deleteIns/{id}")
    public  AjaxResult deleteInstitution(@PathVariable("id") Integer id){
        int result = ability_InstitutionService.deleteAbility_InstitutionInforById(id);
        if(result>0){
            return AjaxResult.success("删除成功");
        }else {
            return AjaxResult.warn("删除失败");
        }
    }

}
